import java.util.Arrays;

public class TestFindMedianSortedArrays {
    public static void main(String[] args) {
        int[] nums1 = {-5,-7,2};
        int[] nums2 = {-2,1,3};
        double ret = findMedianSortedArrays(nums1,nums2);
        System.out.println(ret);
    }

    public static double findMedianSortedArrays(int[] nums1, int[] nums2){
        int m = nums1.length;
        int n = nums2.length;
        if(m == 0 && n == 0){
            return 0;
        }
        if(m == 0){
            if(n%2==0){
                return (nums2[n/2-1]+nums2[n/2]) /2.0;
            }else{
                return nums2[n/2];
            }
        }
        if(n == 0){
            if(m % 2 == 0){
                return (nums1[m/2-1]+nums1[m/2]) /2.0;
            }else{
                return nums1[m/2];
            }
        }
        int[] tmp = new int[m+n];
        System.arraycopy(nums1,0,tmp,0,m);
        System.arraycopy(nums2,0,tmp,m,n);
        Arrays.sort(tmp);
        if((tmp.length) % 2 == 0){
            return (tmp[(tmp.length)/2-1] + tmp[(tmp.length)/2]) /2.0;
        }else{
            return tmp[(tmp.length)/2];
        }
    }
}
